<?php
/**
 * 验收记录模型
 */

namespace app\common\model;

use think\model\concern\SoftDelete;

class Check extends CommonBaseModel {
	use SoftDelete;
	// 自定义选择数据
	public const STATUS_TEXT = [0 => '未验收', 1 => '已验收', 2 => '待审核'];
	protected $name = 'check';
	protected $autoWriteTimestamp = true;

	// 可搜索字段
	public array $searchField = [];

	// 可作为条件的字段
	public array $whereField = ['school_id', 'order_id', 'status'];

	// 可作为多选条件的字段
	public array $multiWhereField = [];

	// 可做为时间
	public array $timeField = ['send_time'];
	protected $json = ['detail'];
	protected $jsonAssoc = true;
	/**
	 * 发货时间获取器
	 */
	public function getSendTimeAttr($value) {
		return date('Y-m-d', $value);
	}

/**
 * 发货时间修改器
 */
	public function setSendTimeAttr($value) {
		return strtotime($value);
	}/**
	 * 状态获取器
	 */
	public function getStatusTextAttr($value, $data): string {
		return self::STATUS_TEXT[$data['status']];
	}

	/**
	 * 关联
	 */
	public function school() {
		return $this->belongsTo(School::class);
	}/**
	 * 关联
	 */
	public function order() {
		return $this->belongsTo(Order::class);
	}
	public function user() {
		return $this->belongsTo(User::class);
	}
}
